home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MacQForth 1.0 / code / disk.4th next >
Encoding:
Text File  |  1995-03-24  |  700 b   |  22 lines  |  [TEXT/ALFA]

  1.  
  2. ( Sample program to read a disk file )
  3.  
  4. create buff 4096 allot  ( only 1st 4k of file )
  5. create str  80   allot  ( name of the file )
  6.  
  7. : get$  ( -- addr )  ( get the name of a file and return the address )
  8.     cr ." File name ? "
  9.     str 80 expect cr ( get the string )
  10.     0 str span + c!  ( NULL terminated )
  11.     str ;     ( return the address of the string )
  12.  
  13. : readfile ( -- )  ( prompt for a file and read it )
  14.     0 get$ fopen  drop  ( open the file, ignore error code  )
  15.     0 buff 4095 fread   ( read the file buffer )
  16.     drop                ( drop ec and leave actual length read )
  17.     0 do
  18.      buff i + @ emit    ( print a character )
  19.     loop
  20.     0 fclose drop  ;    ( close the file )
  21.  
  22.